<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="{{.table.PackageName}}.mapper.{{.table.ClassName}}Mapper">
    
    <resultMap id="{{.table.ClassName}}Result" type="{{.table.PackageName}}.model.{{.table.ClassName}}">
{{range $index, $column := .table.Columns}}
        <result property="{{$column.JavaField}}"    column="{{$column.ColumnName}}"    />
{{end}}

    </resultMap>
{{if eq .table.TplCategory "sub"}}

    <resultMap id="{{.table.ClassName}}{{.table.SubTable.ClassName}}Result" type="{{.table.PackageName}}.model.vo.{{.table.ClassName}}VO" extends="{{.table.ClassName}}Result">
        <collection property="{{.table.SubTable.ClassName | CaseCamelLower }}List" notNullColumn="sub_{{.table.SubTable.PkColumn.ColumnName}}" javaType="java.util.List" resultMap="{{.table.SubTable.ClassName}}Result" />
    </resultMap>

    <resultMap type="{{.table.PackageName}}.model.{{.table.SubTable.ClassName}}" id="{{.table.SubTable.ClassName}}Result">
        {{range $index, $column := .table.SubTable.Columns}}
            <result property="{{$column.JavaField}}"    column="{{$column.ColumnName}}"    />
        {{end}}
    </resultMap>
{{end}}
{{ $length := len .table.Columns }}
    <sql id="select{{.table.ClassName}}Vo">
        select{{range $index, $column := .table.Columns}} `{{$column.ColumnName}}`{{if ne (Sum $index 1) $length}},{{end}}{{end}} from `{{.table.TableName}}`
    </sql>

    <select id="select{{.table.ClassName}}List" parameterType="{{.table.PackageName}}.model.{{.table.ClassName}}" resultMap="{{.table.ClassName}}Result">
        <include refid="select{{.table.ClassName}}Vo"/>
        <where>
{{range $index, $column := .table.Columns}}
{{$queryType := $column.QueryType}}
{{$javaField := $column.JavaField}}
{{$javaType := $column.JavaType}}
{{$columnName := $column.ColumnName}}
{{$AttrName := ($column.JavaField | CaseCamel)}}
{{if eq $column.IsQuery "1"}}
{{if eq $column.QueryType "EQ"}}
            <if test="{{$javaField}} != null {{if eq $javaType "String"}} and {{$javaField}}.trim() != '' {{end}} "> and
                `{{$columnName}}` = #{ {{- $javaField -}} }</if>
{{else if eq $column.QueryType "NE"}}
            <if test="{{$javaField}} != null {{if eq $javaType "String"}} and {{$javaField}}.trim() != '' {{end}} "> and
        `{{$columnName}}` != #{ {{- $javaField -}} }</if>
{{else if eq $column.QueryType "GT"}}
            <if test="{{$javaField}} != null {{if eq $javaType "String"}} and {{$javaField}}.trim() != '' {{end}} "> and
        `{{$columnName}}` &gt; #{ {{- $javaField -}} }</if>
{{else if eq $column.QueryType "GTE"}}
            <if test="{{$javaField}} != null {{if eq $javaType "String"}} and {{$javaField}}.trim() != '' {{end}} "> and
        `{{$columnName}}` &gt;= #{ {{- $javaField -}} }</if>
{{else if eq $column.QueryType "LT"}}
            <if test="{{$javaField}} != null {{if eq $javaType "String"}} and {{$javaField}}.trim() != '' {{end}} "> and
        `{{$columnName}}` &lt; #{ {{- $javaField -}} }</if>
{{else if eq $column.QueryType "LTE"}}
            <if test="{{$javaField}} != null {{if eq $javaType "String"}} and {{$javaField}}.trim() != '' {{end}} "> and
        `{{$columnName}}` &lt;= #{ {{- $javaField -}} }</if>
{{else if eq $column.QueryType "LIKE"}}
            <if test="{{$javaField}} != null {{if eq $javaType "String"}} and {{$javaField}}.trim() != '' {{end}} "> and
        `{{$columnName}}` like concat('%','#{ {{- $javaField -}} }','%') </if>
{{end}}
{{end}}
{{end}}
        </where>
    </select>


    <insert id="batch{{.table.ClassName}}">
        insert into {{.table.TableName}}({{range $index, $column := .table.Columns}} {{$column.ColumnName}}{{if ne (Sum $index 1) $length}},{{end}}{{end}}) values
        <foreach item="item" index="index" collection="list" separator=",">
            ({{range $index, $column := .table.Columns}} #{item.{{- $column.JavaField -}} }{{if ne (Sum $index 1) $length}},{{end}}{{end}})
        </foreach>
    </insert>

</mapper>